class Solution {
    public boolean canJump(int[] nums) {
        int n = nums.length;
        int left = 0, right = 0;
        int i = 0;
        while(i<n) {
            int newLeft = right + 1;
            int newRight= 0;
            for(int j = left; j<= right; j++) {
                newRight = Math.max(newRight, j+nums[j]);
            }

            if(newRight < left) return false;
            left = newLeft;
            right = newRight;
            i = newLeft;
        }
        return true;
    }
}

public class Test {
}
